home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / MPW Goodies / MPW Goodies⁄DTS / AddChange < prev    next >
Text File  |  2022-08-05  |  4KB  |  148 lines

  1. #    AddChange - add changes to a window
  2. #
  3. #    Usage:    AddChange window [commentFile]
  4. #
  5. #    Status:    AddChange may return the following status values:
  6. #
  7. #            0        the change was added
  8. #            1        error
  9. #            4        the user canceled
  10. #
  11. #    AddChange adds a change from the file, commentFile, to the window.
  12. #    The change is inserted at the LastChange marker. If no marker is
  13. #    present, a dialog is presented, allowing the user to add a blank header
  14. #    to the file. If no commentFile is passed, the comment field is left blank.
  15.  
  16. Set CaseSensitive 0
  17. Set Exit 0
  18. Begin
  19.  
  20.     Set Window "{1}"                    # add change to this file (must be open window)
  21.     Set Comment "{2}"                    # get comment from this file (should not be open)
  22.  
  23.     # get short name of window
  24.  
  25.     If "{Window}" =~ /:*([¬:]+:*)*([¬:]+.([a-z]+)®2)®1/
  26.         Set Short "{®1}"
  27.         Set Suffix {®2}
  28.     Else If "{Window}" =~ /:*([¬:]+:*)*([¬:]+)®1/
  29.         Set Short "{®1}"
  30.         Set Suffix ""
  31.     Else
  32.         Exit 1
  33.     End
  34.  
  35.     If "{Suffix}" =~ /[chri]/        # comments for C and Rez
  36.         Set StartComment    "/*"
  37.         Set EndComment        "*/"
  38.         Set Leader            ""
  39.     Else If "{Suffix}" == "cp"        # comments for C++
  40.         Set StartComment    "/*"
  41.         Set EndComment        "*/"
  42.         Set Leader            ""
  43.     Else If "{Suffix}" == "p"        # comments for Pascal
  44.         Set StartComment    "∂{"
  45.         Set EndComment        "∂}"
  46.         Set Leader            ""
  47.     Else If "{Suffix}" == "a"        # comments for assembly language
  48.         Set StartComment    ";"
  49.         Set EndComment        ";"
  50.         Set Leader            ";"
  51.     Else                            # comments for shell scripts, Makefiles etc.
  52.         Set StartComment    "#"
  53.         Set EndComment        "#"
  54.         Set Leader            "#"
  55.     End
  56.  
  57.     # find change history
  58.  
  59.     Find LastChange "{Window}"                    # find the change history
  60.     If {Status} != 0                            # create one if necessary
  61.         Find • "{Window}"                        # go to the top of the window
  62.         Mark /•∂tChange History:[ ∂t]*∂n[ ∂t]*∂n/Δ LastChange "{Window}"
  63.         If {Status} != 0
  64.             If "{Comment}" != ""
  65.                 Confirm -t "There is no “LastChange” marker in “{Short}”. Do you want to add a header?"
  66.                 Set ConfirmStatus {Status}
  67.                 If {ConfirmStatus} == 5            # cancel: report this to the caller
  68.                     Exit 4
  69.                 Else If {ConfirmStatus} == 4    # no: don't add the change
  70.                     Exit 0
  71.                 End                                # yes: go on with life as usual
  72.             End
  73.             If "{Contents}" == ""
  74.                 Set Contents "*** put contents here ***"
  75.             End
  76.             If "{Writers}" == ""
  77.                 Set Writers "*** put writers here ***"
  78.             End
  79.             If "{Copyright}" == ""
  80.                 If "`Date -d`" =~ /[a-z]+, [a-z]+ [0-9]+, ([0-9]+)®1/
  81.                     Set Copyright "© {®1} by Apple Computer, Inc., all rights reserved."
  82.                 Else
  83.                     Set Copyright "*** put copyright here ***"
  84.                 End
  85.             End
  86.             Begin
  87.                 Echo "{StartComment}"
  88.                 Echo "{Leader}∂tFile:∂t∂t{Short}"
  89.                 Echo "{Leader}"
  90.                 Echo "{Leader}∂tContains:∂t{Contents}"
  91.                 Echo "{Leader}"
  92.                 Echo "{Leader}∂tWritten by:∂t{Writers}"
  93.                 Echo "{Leader}"
  94.                 Echo "{Leader}∂tCopyright:∂t{Copyright}"
  95.                 Echo "{Leader}"
  96.                 Echo "{Leader}∂tChange History:"
  97.                 Echo "{Leader}"
  98.                 Echo "{Leader}"
  99.                 Echo "{Leader}∂tTo Do:"
  100.                 Echo "{EndComment}"
  101.                 Echo
  102.             End > "{Window}.§"
  103.             Find !0 "{Window}"
  104.             Find Δ¡3 "{Window}"
  105.             Mark -y § LastChange "{Window}"
  106.         End
  107.     End
  108.  
  109.     # concoct the change line for the change history
  110.  
  111.     If "`Date -d -s`    " =~ /(?«7,8»)®1≈/
  112.         Set ChangeDate "{®1}"
  113.     Else
  114.         Set ChangeDate "??/??/??"
  115.     End
  116.     If "{UserInitials}" == ""            # no initials, use user name instead
  117.         Set UserInitials ""                # in case it was not defined before
  118.         Set TrimmingName "{User}"        # use this for the loop
  119.         Loop
  120.             If "{TrimmingName}" =~ /([a-z])®1[a-z.]* (?*)®2/
  121.                 Set UserInitials {UserInitials}{®1}
  122.                 Set TrimmingName "{®2}"
  123.             Else If "{TrimmingName}" =~ /([a-z])®1[a-z.]*/
  124.                 Set UserInitials {UserInitials}{®1}
  125.                 Break
  126.             Else
  127.                 Set UserInitials "{User}∂n∂t∂t∂t∂t∂t"
  128.                 Break
  129.             End
  130.         End
  131.     End
  132.  
  133.     # put the comment at the top of the change history
  134.  
  135.     Find Δ§ "{Window}"                    # put the comment into the change history
  136.     Echo -n "{Leader}∂t∂t{ChangeDate}∂t{UserInitials}∂t∂t" >> "{Window}.§"
  137.     Catenate "{Comment}" >> "{Window}.§"
  138.     If {Status} != 0
  139.         Echo -n "*** put comment here ***" >> "{Window}.§"
  140.     End
  141.     Echo >> "{Window}.§"
  142.  
  143.     # mark the change history again
  144.  
  145.     Mark -y § LastChange "{Window}"
  146.  
  147. End ∑Dev:Null
  148.